package com.freight.tws.controller.app;

import com.freight.common.core.constant.Constants;
import com.freight.common.core.domain.R;
import com.freight.common.core.web.controller.BaseController;
import com.freight.tws.api.domain.Driver;
import com.freight.tws.domain.vo.UpdatePasswordVo;
import com.freight.tws.service.IDriverService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 手机端 - 司机信息
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping(Constants.APP_URL + "/")
public class AppDriverController extends BaseController {

    private final IDriverService iDriverService;

    /**
     * 忘记密码 修改密码（需要短信验证码）
     */
    @PostMapping("forgetUpdatePassword")
    public R<?> forgetUpdatePassword(@RequestBody UpdatePasswordVo updatePasswordVo) {
        return iDriverService.forgetUpdatePassword(updatePasswordVo) > 0 ? R.ok() : R.fail();
    }

    /**
     * 修改密码（需要旧密码）
     */
    @PostMapping("resetPassword")
    public R<?> resetPassword(@RequestBody UpdatePasswordVo updatePasswordVo) {
        return iDriverService.resetPassword(updatePasswordVo) > 0 ? R.ok() : R.fail();
    }

    /**
     * 提交实名认证
     */
    @PostMapping("cert")
    public R cert(HttpServletRequest request, @RequestBody Driver driver) {
        return iDriverService.toCert(request, driver) > 0 ? R.ok() : R.fail();
    }

}
